package com.ruoyi.web.controller.safe;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.safe.domain.ChemicalHandling;
import com.ruoyi.safe.service.IChemicalHandlingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 化学品处理Controller
 * 
 * @author yxf
 * @date 2021-08-10
 */
@RestController
@RequestMapping("/safe/handling")
public class ChemicalHandlingController extends BaseController
{
    @Autowired
    private IChemicalHandlingService chemicalHandlingService;

    /**
     * 查询化学品处理列表
     */
    @PreAuthorize("@ss.hasPermi('safe:handling:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChemicalHandling chemicalHandling)
    {
        startPage();
        List<ChemicalHandling> list = chemicalHandlingService.selectChemicalHandlingList(chemicalHandling);
        return getDataTable(list);
    }

    /**
     * 导出化学品处理列表
     */
    @PreAuthorize("@ss.hasPermi('safe:handling:export')")
    @Log(title = "化学品处理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ChemicalHandling chemicalHandling)
    {
        List<ChemicalHandling> list = chemicalHandlingService.selectChemicalHandlingList(chemicalHandling);
        ExcelUtil<ChemicalHandling> util = new ExcelUtil<ChemicalHandling>(ChemicalHandling.class);
        return util.exportExcel(list, "化学品处理数据");
    }

    /**
     * 获取化学品处理详细信息
     */
    @PreAuthorize("@ss.hasPermi('safe:handling:query')")
    @GetMapping(value = "/{chId}")
    public AjaxResult getInfo(@PathVariable("chId") Long chId)
    {
        return AjaxResult.success(chemicalHandlingService.selectChemicalHandlingById(chId));
    }

    /**
     * 新增化学品处理
     */
    @PreAuthorize("@ss.hasPermi('safe:handling:add')")
    @Log(title = "化学品处理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChemicalHandling chemicalHandling)
    {
        return toAjax(chemicalHandlingService.insertChemicalHandling(chemicalHandling));
    }

    /**
     * 修改化学品处理
     */
    @PreAuthorize("@ss.hasPermi('safe:handling:edit')")
    @Log(title = "化学品处理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChemicalHandling chemicalHandling)
    {
        return toAjax(chemicalHandlingService.updateChemicalHandling(chemicalHandling));
    }

    /**
     * 删除化学品处理
     */
    @PreAuthorize("@ss.hasPermi('safe:handling:remove')")
    @Log(title = "化学品处理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{chIds}")
    public AjaxResult remove(@PathVariable Long[] chIds)
    {
        return toAjax(chemicalHandlingService.deleteChemicalHandlingByIds(chIds));
    }
}
